﻿using System;
using System.Text;
using System.Drawing;
using System.Collections.Generic;
using Ex03.VehicalsObjectModel;

namespace Ex03.GarageManagementSystem.Console
{
    public class ConsoleGarageManagement
    {
        // Members
        private readonly Dictionary<char, GarageMenuAction> k_MenuActions;
        private readonly Dictionary<int, string> k_VehicalTypes;
        private VehicalsGarage m_Garage;

        // Ctor
        public ConsoleGarageManagement()
        {
            m_Garage = new VehicalsGarage();
            k_MenuActions = new Dictionary<char, GarageMenuAction>();
            k_VehicalTypes = new Dictionary<int, string>();
            initActions();
            initTypes();
        }

        private void initTypes()
        {
            int currTypeIndex = 1;
            foreach (string currTypeName in VehicalCreator.AvailableTypes)
            {
                k_VehicalTypes.Add(currTypeIndex++, currTypeName);
            }
        }

        private void initActions()
        {
            int currActionIndex = 1;
            k_MenuActions.Add((char)(currActionIndex + '0'), new GarageMenuAction((char)(currActionIndex++ + '0'), "Add new vehical to the garage", eGarageActionType.AddNewVehical));
            k_MenuActions.Add((char)(currActionIndex + '0'), new GarageMenuAction((char)(currActionIndex++ + '0'), "Show all the cars in the garage", eGarageActionType.ShowAllCars));
            k_MenuActions.Add((char)(currActionIndex + '0'), new GarageMenuAction((char)(currActionIndex++ + '0'), "Show all the cars in the garage filtered by status", eGarageActionType.ShowCarsByStatus));
            k_MenuActions.Add((char)(currActionIndex + '0'), new GarageMenuAction((char)(currActionIndex++ + '0'), "Fix a vehical in maintainance", eGarageActionType.FixVehical));
            k_MenuActions.Add((char)(currActionIndex + '0'), new GarageMenuAction((char)(currActionIndex++ + '0'), "Pay for a vehical", eGarageActionType.PayForVehical));
            k_MenuActions.Add((char)(currActionIndex + '0'), new GarageMenuAction((char)(currActionIndex++ + '0'), "Infalte a vehical wheel", eGarageActionType.InflateWheel));
            k_MenuActions.Add((char)(currActionIndex + '0'), new GarageMenuAction((char)(currActionIndex++ + '0'), "Fule a vehical", eGarageActionType.FuleVehical));
            k_MenuActions.Add((char)(currActionIndex + '0'), new GarageMenuAction((char)(currActionIndex++ + '0'), "Charge a vehical", eGarageActionType.ChargeVehical));
            k_MenuActions.Add((char)(currActionIndex + '0'), new GarageMenuAction((char)(currActionIndex++ + '0'), "Show the full details of a vehical", eGarageActionType.ShowVehicalDetails));
            k_MenuActions.Add('0', new GarageMenuAction('0', "Exit the garage system", eGarageActionType.Exit));
        }

        // Methods

        /// <summary>
        /// Starts the garage managment console system
        /// </summary>
        public void Start()
        {
            bool exitConfirmed = false;
            eGarageActionType currActionType;

            // Handle the main menu until exit is requeted
            do
            {
                System.Console.Clear();
                showWelcome();
                showMainMenu();
                currActionType = getActionFrom();
                switch (currActionType)
                {
                    case eGarageActionType.AddNewVehical:
                        addNewVehical();
                        break;

                    case eGarageActionType.ShowAllCars:
                        showAllVehicals();
                        break;

                    case eGarageActionType.ShowCarsByStatus:
                        showCarsByStatus();
                        break;

                    case eGarageActionType.FixVehical:
                        fixVehical();
                        break;

                    case eGarageActionType.PayForVehical:
                        payForVehical();
                        break;

                    case eGarageActionType.InflateWheel:
                        inflateVehicalWheel();
                        break;

                    case eGarageActionType.FuleVehical:
                        fuleVehical();
                        break;

                    case eGarageActionType.ChargeVehical:
                        chargeVehical();
                        break;

                    case eGarageActionType.ShowVehicalDetails:
                        showVehicalDetails();
                        break;

                    case eGarageActionType.Exit:
                        exitConfirmed = confirmExit();
                        break;
                }
            }
            while (currActionType != eGarageActionType.Exit || !exitConfirmed);
            
            // Show goodbye message
            showGoodbye();
        }

        #region Action Handling Methods

        private void showVehicalDetails()
        {
            if (m_Garage.Vehicals.Count == 0)
            {
                writeLine("There are no vehicals in the garage, Press Enter to return");
                System.Console.ReadLine();
            }
            else
            {
                // Choose a vehical
                GarageVehical vehical = chooseVehical(getAllVehicals());

                // Show Gemeral details
                printVehicalFullDetails(vehical);
            }
        }

        private void chargeVehical()
        {
            // Choose a vehical
            List<GarageVehical> electricVehicals = m_Garage.GetElectricVehicals();
            if (electricVehicals.Count == 0)
            {
                writeLine("There are no electric vehicals in the garage, Press Enter to return");
                System.Console.ReadLine();
            }
            else
            {
                // Choose a fule vehical
                GarageVehical vehical = chooseVehical(electricVehicals);
                IElectricVehical electricVehical = vehical.MaintainedVehical as IElectricVehical;

                // Get fule to add
                writeLine(string.Format(
                    "Electric vehical {0} of ({1}/{2} {3}%)",
                    vehical.MaintainedVehical.LicenseNumber,
                    electricVehical.CurrentDuration,
                    electricVehical.MaximumDuration,
                    vehical.MaintainedVehical.CurrentEnregyPercent));
                write("Type the number of minutes to add: ");
                int addedMinutes = (int)getNumber();

                try
                {
                    (vehical.MaintainedVehical as IElectricVehical).Charge(addedMinutes);
                    writeLine(string.Format(
                        "Vehical {0} charged to ({1}/{2} {3}%), Press Enter to return to main menu.",
                        vehical.MaintainedVehical.LicenseNumber,
                        electricVehical.CurrentDuration,
                        electricVehical.MaximumDuration,
                        vehical.MaintainedVehical.CurrentEnregyPercent));
                }
                catch (ValueOutOfRangeException e)
                {
                    writeLine(string.Format("Invalid duration, valid time is between {0} and {1}", e.MinValue, e.MaxValue));
                    writeLine("Press Enter to return to main menu");
                }
                finally
                {
                    System.Console.ReadLine();
                }
            }
        }

        private void fuleVehical()
        {
            // Choose a vehical
            List<GarageVehical> fuleVehicals = m_Garage.GetFuleVehicals();
            if (fuleVehicals.Count == 0)
            {
                writeLine("There are no fule vehicals in the garage, Press Enter to return");
                System.Console.ReadLine();
            }
            else
            {
                // Choose a fule vehical
                GarageVehical vehical = chooseVehical(fuleVehicals);
                IFuleVehical fuleVehical = vehical.MaintainedVehical as IFuleVehical;

                // Get fule to add
                writeLine(string.Format(
                    "Fule vehical {0} of {4} ({1}/{2} {3}%)", 
                    vehical.MaintainedVehical.LicenseNumber,
                    fuleVehical.CurrentLitteres, 
                    fuleVehical.MaximumLitteres,
                    vehical.MaintainedVehical.CurrentEnregyPercent,
                    fuleVehical.FuleType.ToString()));
                write("Type the number of literes to add: ");
                float addedFule = getNumber();

                // Get the fule type
                eFuleType fuleType = getFuleType();
                try
                {
                    (vehical.MaintainedVehical as IFuleVehical).Fule(fuleType, addedFule);
                    writeLine(string.Format(
                        "Vehical {0} fuled to ({1}/{2} {3}%), Press Enter to return to main menu.",
                        vehical.MaintainedVehical.LicenseNumber,
                        fuleVehical.CurrentLitteres,
                        fuleVehical.MaximumLitteres,
                        vehical.MaintainedVehical.CurrentEnregyPercent));
                }
                catch (ValueOutOfRangeException e)
                {
                    writeLine(string.Format("Invalid amount of fule, valid amount is between {0} and {1}", e.MinValue, e.MaxValue));
                    writeLine("Press Enter to return to main menu");
                }
                catch (ArgumentException)
                {
                    writeLine("Incompatible fule type, press Enter to return to main menu");
                }
                finally
                {
                    System.Console.ReadLine();
                }
            }
        }

        private void inflateVehicalWheel()
        {
            if (m_Garage.Vehicals.Count == 0)
            {
                writeLine("There are no vehicals in the garage, Press Enter to return");
                System.Console.ReadLine();
            }
            else
            {
                // Get the vehical
                GarageVehical vehical = chooseVehical(getAllVehicals());

                // Chose a wheel
                VehicalWheel wheel = getWheel(vehical);

                // Get the target PSI
                write("Enter the target PSI: ");
                float newPSI = getNumber();
                try
                {
                    // Inflate the wheel
                    wheel.Inflate(newPSI);
                    writeLine(string.Format("Wheel inflated to {0} PSI, press Enter to continue", wheel.CurrentPSI));
                }
                catch (ValueOutOfRangeException e)
                {
                    writeLine(string.Format("Invalid target PSI, valid PSI is between {0} and {1}, Press Enter to return to main menu", e.MinValue, e.MaxValue));
                }
                finally
                {
                    System.Console.ReadLine();
                }
            }
        }

        private void payForVehical()
        {
            if (m_Garage.Vehicals.Count == 0)
            {
                writeLine("There are no vehicals in the garage, Press Enter to return");
                System.Console.ReadLine();
            }
            else
            {
                // Get the vehical
                GarageVehical chosenVehical = chooseVehical(getAllVehicals());

                // Change the status
                chosenVehical.PayForVehical();
                m_Garage.RemoveVehical(chosenVehical.MaintainedVehical);
                writeLine(string.Format("Vehical {0} payed for and parted the garage. Press Enter to continue", chosenVehical.MaintainedVehical.LicenseNumber));
                System.Console.ReadLine();
            }
        }

        private void fixVehical()
        {
            if (m_Garage.Vehicals.Count == 0)
            {
                writeLine("There are no vehicals in the garage, Press Enter to return");
                System.Console.ReadLine();
            }
            else
            {
                // Get the vehical
                GarageVehical chosenVehical = chooseVehical(getAllVehicals());

                // Change the status
                chosenVehical.FixVehical();
                writeLine(string.Format("Vehical {0} fixed. Press Enter to continue", chosenVehical.MaintainedVehical.LicenseNumber));
            }

            System.Console.ReadLine();
        }

        private void showCarsByStatus()
        {
            // Get a status
            writeLine();
            writeLine("Choose status to filer: ");
            eVehicalStatus filterStatus = getValidStatus(getFilterStatus());

            // Get the vehicals and print them
            List<GarageVehical> filteredVehicals = m_Garage.GetVehicalsByStatus(filterStatus);
            writeLine();
            writeLine(string.Format("Showing {0} vehicals:", filterStatus.ToString()));
            showVehicals(filteredVehicals);
            writeLine();
            writeLine("Press Enter to continue");
            System.Console.ReadLine();
        }

        private void showAllVehicals()
        {
            // Put all the vehicals in a list
            showVehicals(getAllVehicals());
            writeLine();
            writeLine("Press Enter to continue");
            System.Console.ReadLine();
        }

        private void showVehicals(List<GarageVehical> i_Vehicals)
        {
            const string v_LineFormat = " {0,-11}| {1,-18}| {2,-19}| {3}";

            // Print title
            writeLine();
            writeLine(string.Format(v_LineFormat, "License No", "Type", "Status", "Owners Name"));
            writeLine("------------|-------------------|--------------------|--------------");

            if (i_Vehicals.Count == 0)
            {
                writeLine(" - No vehicals found");
            }
            else
            {
                // Get all the vehicals in the garage
                foreach (GarageVehical currVehical in i_Vehicals)
                {
                    writeLine(string.Format(
                        v_LineFormat,
                        currVehical.MaintainedVehical.LicenseNumber,
                        currVehical.MaintainedVehical.GetTypeName(),
                        currVehical.VehicalStatus.ToString(),
                        currVehical.OwnersName));
                }
                
                writeLine("-------------");
                writeLine(string.Format("{0} vehicals.", i_Vehicals.Count));
            }
        }

        private void addNewVehical()
        {
            // Show the possible types
            writeLine("Choose a vehical type to add:");
            foreach (KeyValuePair<int, string> currType in k_VehicalTypes)
            {
                writeLine(string.Format("  {0}: {1}", currType.Key, currType.Value));
            }

            // Get the type to create
            int vehicalTypeCode = getVehicalTypeCode();
            string ownersName;
            string licenseNumber;
            object value1;
            object value2;

            // Get the specific details
            write("Enter the owners name: ");
            ownersName = System.Console.ReadLine();
            getVehicalDetails(k_VehicalTypes[vehicalTypeCode], out licenseNumber, out value1, out value2);

            // Create the vehical object
            Vehical createdVehical = null;
            try
            {
                createdVehical = VehicalCreator.CreateVehical(k_VehicalTypes[vehicalTypeCode], licenseNumber, value1, value2);
            }
            catch (Exception creationException)
            {
                writeLine(string.Format("Error creating vehical: {0}", creationException.Message));
                writeLine("Press Enter to return to main menu");
                System.Console.ReadLine();
            }

            // If the vehical is created, add it to the garage
            if (createdVehical != null)
            {
                try
                {
                    try
                    {
                        // Get PSI for wheels and inflate them
                        getPSIInflation(createdVehical);
                    }
                    catch (ValueOutOfRangeException inflationException)
                    {
                        writeLine(string.Format("Inflation error: {0}", inflationException.Message));
                    }
                    
                    GarageVehical addedVehical = m_Garage.AddVehical(createdVehical, ownersName);
                    writeLine("Vehical added to the garage, see full details:");
                    printVehicalFullDetails(addedVehical);
                }
                catch (ArgumentException)
                {
                    writeLine("Error adding the vehical to the garage");
                    writeLine("Either owners name is invalid or vehical already exists");
                    writeLine("Press Enter to return to main menu");
                    System.Console.ReadLine();
                }
            }
        }

        private void getPSIInflation(Vehical createdVehical)
        {
            write(string.Format(
                "Enter PSI for the wheels ({0} wheels, max PSI: {1}): ",
                createdVehical.Wheels.Count,
                createdVehical.Wheels[0].MaxPSI));
            float wheelsPSI = getNumber();

            foreach (VehicalWheel currWheel in createdVehical.Wheels)
            {
                currWheel.Inflate(wheelsPSI);
            }
        }

        #endregion

        #region Messages

        private void writeLine()
        {
            writeLine(string.Empty);
        }

        private void writeLine(string i_Message)
        {
            write(i_Message);
            System.Console.WriteLine();
        }

        private void write(string i_Message)
        {
            System.Console.Write(i_Message);
        }

        private void showWelcome()
        {
            writeLine("Welcome to the Garage Management System!");
            writeLine("----------------------------------------");
            writeLine();
        }

        private void showGoodbye()
        {
            writeLine();
            writeLine("Thank you and goodbye.");
        }

        private void showMainMenu()
        {
            writeLine("Please make your choise:");

            // Show all the possible action items
            foreach (GarageMenuAction currAction in k_MenuActions.Values)
            {
                writeLine(string.Format("  {0}", currAction.ToString()));
            }
        }

        private void printWheels(GarageVehical i_Vehical)
        {
            int currWheelIndex = 1;
            foreach (VehicalWheel currWheel in i_Vehical.MaintainedVehical.Wheels)
            {
                writeLine(string.Format("  {0}: Wheel No.{0} - {1}/{2} PSI", currWheelIndex++, currWheel.CurrentPSI, currWheel.MaxPSI));
            }
        }

        private void printVehicalFullDetails(GarageVehical vehical)
        {
            writeLine();
            writeLine(string.Format("{1} number {0}", vehical.MaintainedVehical.LicenseNumber, vehical.MaintainedVehical.GetTypeName()));
            writeLine("------------------------------------------------");
            writeLine(string.Format("Owners: {0}\t Status: {1}", vehical.OwnersName, vehical.VehicalStatus.ToString()));

            // Show specific vehical type details
            if (vehical.MaintainedVehical is PrivateCar)
            {
                PrivateCar car = vehical.MaintainedVehical as PrivateCar;
                writeLine(string.Format("Color: {0}\t Doors Number: {1}", car.CarColor.Name, car.NumOfDoors));
            }
            else if (vehical.MaintainedVehical is Truck)
            {
                Truck truck = vehical.MaintainedVehical as Truck;
                writeLine(string.Format("Cargo hold: {0} tons", truck.CurrentCargoLoad));
            }

            // Show energy details
            if (vehical.MaintainedVehical is IFuleVehical)
            {
                IFuleVehical fuleVehical = vehical.MaintainedVehical as IFuleVehical;
                writeLine(string.Format(
                    "Fule: {0} out of {1} litteres ({2}%) of {3}",
                    fuleVehical.CurrentLitteres,
                    fuleVehical.MaximumLitteres,
                    vehical.MaintainedVehical.CurrentEnregyPercent,
                    fuleVehical.FuleType.ToString()));
            }
            else if (vehical.MaintainedVehical is IElectricVehical)
            {
                IElectricVehical electricVehical = vehical.MaintainedVehical as IElectricVehical;
                writeLine(string.Format(
                    "Energy: {0} out of {1} minutes ({2}%)",
                    electricVehical.CurrentDuration,
                    electricVehical.MaximumDuration,
                    vehical.MaintainedVehical.CurrentEnregyPercent));
            }

            // Show wheel details
            writeLine("Wheels: ");
            printWheels(vehical);

            // Prompt
            writeLine();
            writeLine("Press Enter to return to main menu");
            System.Console.ReadLine();
        }

        #endregion

        #region Input handlers

        private eGarageActionType getActionFrom()
        {
            bool isValidInput = false;
            eGarageActionType inputAction = eGarageActionType.Exit;

            // Get the input from the user, until its valid
            do
            {
                // Get the input action
                write("> ");
                string input = System.Console.ReadLine();

                // If it is not an action key (1 char)
                if (input.Length != 1)
                {
                    writeLine("Invalid action key, please try again.");
                }
                else
                {
                    char actionKey = input[0];

                    // Check if the action exists in the menu
                    if (!k_MenuActions.ContainsKey(actionKey))
                    {
                        writeLine("Action doesnt exist, please pick an action from the menu.");
                    }
                    else
                    {
                        isValidInput = true;
                        inputAction = k_MenuActions[actionKey].ActionType;
                    }
                }
            }
            while (!isValidInput);

            return inputAction;
        }

        private bool confirmExit()
        {
            const string v_ExitCode = "Y";

            writeLine("Are you sure you want to exit?");
            writeLine(string.Format("Press {0} to confirm", v_ExitCode));

            // Check if the input equels the exit code
            return System.Console.ReadLine().ToUpper() == v_ExitCode;
        }

        private eVehicalStatus getValidStatus(Dictionary<int, eVehicalStatus> i_PossibleStatus)
        {
            const string v_LineFormat = "  {0}: {1}";
            eVehicalStatus inputStatus = eVehicalStatus.UnderMaintainance;

            // Show the possible values
            foreach (KeyValuePair<int, eVehicalStatus> currStatus in i_PossibleStatus)
            {
                writeLine(string.Format(v_LineFormat, currStatus.Key, currStatus.Value.ToString()));
            }

            // Get the status
            bool validInput = false;
            do
            {
                int numberInput;

                // Get the input
                write(" >");
                string input = System.Console.ReadLine();

                // Check if its a valid action
                if (int.TryParse(input, out numberInput) &&
                   i_PossibleStatus.ContainsKey(numberInput))
                {
                    // Convert the input to its status
                    inputStatus = (eVehicalStatus)numberInput;
                    validInput = true;
                }
                else
                {
                    writeLine("Invalid status, try again.");
                }
            }
            while (!validInput);

            return inputStatus;
        }

        private VehicalWheel getWheel(GarageVehical i_Vehical)
        {
            // Show the wheels
            writeLine("Choose a wheel: ");
            printWheels(i_Vehical);

            int wheelNumber;
            bool validWheelNumber = false;
            do
            {
                // Get a wheel number
                write(" > ");
                wheelNumber = (int)getNumber();
                validWheelNumber = wheelNumber >= 1 && wheelNumber <= i_Vehical.MaintainedVehical.Wheels.Count;

                // Show error message if needed
                if (!validWheelNumber)
                {
                    writeLine("Wheel number does not exist, please pick a wheel number from the list.");
                }
            }
            while (!validWheelNumber);

            return i_Vehical.MaintainedVehical.Wheels[wheelNumber - 1];
        }

        private GarageVehical chooseVehical(List<GarageVehical> i_VehicalsList)
        {
            // Show all the vehicals in the garage
            showVehicals(i_VehicalsList);

            // Get the chosen vehical
            string licenseNumber;
            GarageVehical vehical = null;

            do
            {
                write("Type a license number form the list: ");
                licenseNumber = System.Console.ReadLine();
                bool invalidFormat = false;
                try
                {
                    // Check if the license is valid
                    if (Vehical.isValidLicenseNumber(licenseNumber))
                    {
                        // if the vehical exists - get it
                        vehical = m_Garage.GetVehical(licenseNumber);
                    }
                }
                catch (FormatException)
                {
                    invalidFormat = true;
                    writeLine(string.Format("{0} is not a valid license number, try again.", licenseNumber));
                }

                // If the format is valid, but the vehical doesnt exist
                if (!invalidFormat && vehical == null)
                {
                    writeLine(string.Format("There is no vehical with the license number {0}", licenseNumber));
                }
            }
            while (vehical == null);

            return vehical;
        }

        private Dictionary<int, eVehicalStatus> getFilterStatus()
        {
            Dictionary<int, eVehicalStatus> statusToFilter = new Dictionary<int, eVehicalStatus>();
            statusToFilter.Add((int)eVehicalStatus.UnderMaintainance, eVehicalStatus.UnderMaintainance);
            statusToFilter.Add((int)eVehicalStatus.Fixed, eVehicalStatus.Fixed);

            return statusToFilter;
        }

        private float getNumber()
        {
            bool validNumber = false;
            float inputNumber;

            do
            {
                // Check if the input is a valid number
                if (float.TryParse(System.Console.ReadLine(), out inputNumber))
                {
                    validNumber = true;
                }
                else
                {
                    writeLine("Invalid number, try again.");
                }
            }
            while (!validNumber);

            return inputNumber;
        }

        private List<GarageVehical> getAllVehicals()
        {
            List<GarageVehical> allVehicals = new List<GarageVehical>();
            foreach (GarageVehical currVehical in m_Garage.Vehicals)
            {
                allVehicals.Add(currVehical);
            }

            return allVehicals;
        }

        private int getVehicalTypeCode()
        {
            int inputType;
            bool validType = false;
            do
            {
                inputType = (int)getNumber();
                if (k_VehicalTypes.ContainsKey(inputType))
                {
                    validType = true;
                }
                else
                {
                    writeLine("Invalid vehical type, please pick a type from the list.");
                }
            }
            while (!validType);
            return inputType;
        }

        private eFuleType getFuleType()
        {
            eFuleType fuleType = eFuleType.Soler;

            // Make a list of possible options
            Dictionary<int, eFuleType> possibleTypes = new Dictionary<int, eFuleType>();
            possibleTypes.Add(1, eFuleType.Octane95);
            possibleTypes.Add(2, eFuleType.Octane96);
            possibleTypes.Add(3, eFuleType.Octane98);
            possibleTypes.Add(4, eFuleType.Soler);

            // Show the possible options
            writeLine("Enter fule type: ");
            foreach (KeyValuePair<int, eFuleType> currType in possibleTypes)
            {
                writeLine(string.Format("  {0}: {1}", currType.Key, currType.Value.ToString()));
            }

            // Get the type            
            bool validChoice = false;
            do
            {
                // Get the option from the user
                write("> ");
                int option = (int)getNumber();

                // Check if its valid
                validChoice = possibleTypes.ContainsKey(option);
                if (!validChoice)
                {
                    writeLine("Invalid choice, please choose a fule type from the list.");
                }
                else
                {
                    // Get the fule type by the option
                    fuleType = possibleTypes[option];
                }
            }
            while (!validChoice);

            return fuleType;
        }

        private Color getColor()
        {
            bool validColor = false;
            Color inputColor;
            do
            {
                inputColor = Color.FromName(System.Console.ReadLine());
                validColor = inputColor.IsKnownColor;
                if (!validColor)
                {
                    writeLine("Invalid color, please pick a known color");
                }
            }
            while (!validColor);

            return inputColor;
        }

        private void getVehicalDetails(string vehicalType, out string licenseNumber, out object value1, out object value2)
        {
            value1 = null;
            value2 = null;

            // Get a license number
            write("Enter a license number: ");
            licenseNumber = System.Console.ReadLine();

            // Check the type and input accordingly
            if (vehicalType.Contains("Car"))
            {
                write("Type the number of doors in the car: ");
                value1 = (int)getNumber();
                write("Type the color of the car: ");
                value2 = (Color)getColor();
            }
            else if (vehicalType.Contains("Truck"))
            {
                write("Type the cargo load of the truck (in tons): ");
                value1 = getNumber();
            }
        }

        #endregion
    }
}
